//###############
//FILE : FilterManager.java
//WRITER : Yaron Dinur, yarondi, 200184992
//WRITER : Yuval Ran, yuvran21, 032513483
//EXERCISE : oop ex1 2011
//DESCRIPTION:
//
//###############

package filters;

import java.io.File;
import java.util.ArrayList;

public class FilterManager {
		
	public static void runFilters(ArrayList<File> files, 
								  ArrayList<FileFilter> filters){
		ArrayList<File> notPassed = new ArrayList<File>(files);
		for (FileFilter filter : filters){
			if (filter == null){
				cleanUp(files, notPassed);
				notPassed = new ArrayList<File>(files);
			}
			else
				for (File f : notPassed) {
					if (filter.accept(f))
						notPassed.remove(f);
				}
		}
		
	}
	
	private static void cleanUp(ArrayList<File> files, ArrayList<File> toRemove){
		for(File f : toRemove)
			files.remove(f);
	}

}
